﻿using HookupAppForm.Dto;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HookupAppForm.MyUserControl
{
    public partial class UserControlTakeOff : UserControl
    {
        private APIClient client;
        private HKP_TakeoffDto dto { get; set; }
        private HKP_ToolDto tool { get; set; }
        private double Distence { get; set; }
        private double FitDistence { get; set; }
        public UserControlTakeOff(HKP_TakeoffDto _dto, APIClient _client, HKP_ToolDto _tool,double _fitDistence)
        {
            InitializeComponent();
            dto = _dto ?? throw new ArgumentNullException(nameof(_dto));
            client = _client;
            TakeOff.Text = dto.TakeoffNo;
            
            tool = _tool;
            FitDistence = _fitDistence;

            Distence = Math.Round(Utils.GetDistance(Convert.ToInt32(dto.X), Convert.ToInt32(dto.Y), Convert.ToInt32(tool.X), Convert.ToInt32(tool.Y)) / 100, 2);

            bool fit1 = !dto.Used && dto.Enabled;
            bool fit2 = Distence <= FitDistence;
            TakeOff.ForeColor = fit1 && fit2 ? Color.Green : Color.Red;
        }

        private void toolStripMenuItemAlt_Click(object sender, EventArgs e)
        {
            FormTakeOff form = new FormTakeOff(dto, client);
            form.ShowDialog();
        }

        private void TakeOff_MouseHover(object sender, EventArgs e)
        {
            
            StringBuilder tips = new StringBuilder();
            tips.AppendLine("接点编号：" + dto.TakeoffNo);
            tips.AppendLine("所属系统：" + dto.SysName);
            tips.AppendLine("接点尺寸：" + dto.OutSize + dto.OutSizeUnit);
            tips.AppendLine("接点流量：" + dto.FlowPeak + dto.FlowUnit);
            tips.AppendLine("接点类型：" + dto.OutType);
            tips.AppendLine("已使用：" + dto.Used);
            tips.AppendLine("接点启用：" + dto.Enabled);
            tips.AppendLine("接点坐标：X=" + dto.X.ToString()+"，Y="+dto.Y.ToString());
            tips.AppendLine("机台名称：" + tool.ToolModel + tool.ToolName);
            tips.AppendLine("机台坐标：X=" + tool.X.ToString() + "，Y=" + tool.Y.ToString());
            tips.AppendLine("距离：" + Distence.ToString() + "m");

            this.toolTipM.SetToolTip(this.TakeOff, tips.ToString());
        }
    }
}
